# The following reproduces Figure 6
rm(list = ls())
setwd("")
peru <- read.csv("gps.csv", sep = ";", header = T, stringsAsFactors = F)

ll <- matrix(unlist(strsplit(peru$Geocode, ",")), byrow = T, ncol = 2)
peru <- data.frame(peru[, -2], ll, stringsAsFactors = F)
peru[, 3:4] <- apply(peru[, 3:4], 2, as.numeric)
colnames(peru) <- c("treat", "village", "lon", "lat")

require(ggmap)
theme_set(theme_bw(16))

## set map center to midpoint of lon/lat ranges

location <- paste(min(peru[, 3]) + (diff(range(peru[, 3])/2)), 
                  min(peru[, 4]) + (diff(range(peru[, 4])/2)))


# stamen, toner -> preferred map

m1 <- qmap(location, zoom = 11, legend = "topleft",
           maptype = 'toner', source = 'stamen')
m1 <- m1 + geom_point(aes(x = lat, y = lon, shape = treat), data = peru, size = 3)
m1 <- m1 + geom_text(data = peru, aes(x = lat, y = lon, label = village), 
                   size = 3, vjust = -0.7, hjust = 0.5)
m1
ggsave("map_peru.pdf", width = 8, height = 8)
